/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class Items
    {
    
        private  CorrectedQuery correctedQueryField;
        private String qidField;

        private String engineQueryField;

        private Decimal? totalResultsField;

        private Decimal? totalPagesField;

        private  SearchResultsMap searchResultsMapField;
        private  List<Item> itemField;


        /// <summary>
        /// Gets and sets the CorrectedQuery property.
        /// </summary>
        [XmlElementAttribute(ElementName = "CorrectedQuery")]
        public CorrectedQuery CorrectedQuery
        {
            get { return this.correctedQueryField ; }
            set { this.correctedQueryField = value; }
        }



        /// <summary>
        /// Sets the CorrectedQuery property
        /// </summary>
        /// <param name="correctedQuery">CorrectedQuery property</param>
        /// <returns>this instance</returns>
        public Items WithCorrectedQuery(CorrectedQuery correctedQuery)
        {
            this.correctedQueryField = correctedQuery;
            return this;
        }



        /// <summary>
        /// Checks if CorrectedQuery property is set
        /// </summary>
        /// <returns>true if CorrectedQuery property is set</returns>
        public Boolean IsSetCorrectedQuery()
        {
            return this.correctedQueryField != null;
        }




        /// <summary>
        /// Gets and sets the Qid property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Qid")]
        public String Qid
        {
            get { return this.qidField ; }
            set { this.qidField= value; }
        }



        /// <summary>
        /// Sets the Qid property
        /// </summary>
        /// <param name="qid">Qid property</param>
        /// <returns>this instance</returns>
        public Items WithQid(String qid)
        {
            this.qidField = qid;
            return this;
        }



        /// <summary>
        /// Checks if Qid property is set
        /// </summary>
        /// <returns>true if Qid property is set</returns>
        public Boolean IsSetQid()
        {
            return  this.qidField != null;

        }


        /// <summary>
        /// Gets and sets the EngineQuery property.
        /// </summary>
        [XmlElementAttribute(ElementName = "EngineQuery")]
        public String EngineQuery
        {
            get { return this.engineQueryField ; }
            set { this.engineQueryField= value; }
        }



        /// <summary>
        /// Sets the EngineQuery property
        /// </summary>
        /// <param name="engineQuery">EngineQuery property</param>
        /// <returns>this instance</returns>
        public Items WithEngineQuery(String engineQuery)
        {
            this.engineQueryField = engineQuery;
            return this;
        }



        /// <summary>
        /// Checks if EngineQuery property is set
        /// </summary>
        /// <returns>true if EngineQuery property is set</returns>
        public Boolean IsSetEngineQuery()
        {
            return  this.engineQueryField != null;

        }


        /// <summary>
        /// Gets and sets the TotalResults property.
        /// </summary>
        [XmlElementAttribute(ElementName = "TotalResults")]
        public Decimal TotalResults
        {
            get { return this.totalResultsField.GetValueOrDefault() ; }
            set { this.totalResultsField= value; }
        }



        /// <summary>
        /// Sets the TotalResults property
        /// </summary>
        /// <param name="totalResults">TotalResults property</param>
        /// <returns>this instance</returns>
        public Items WithTotalResults(Decimal totalResults)
        {
            this.totalResultsField = totalResults;
            return this;
        }



        /// <summary>
        /// Checks if TotalResults property is set
        /// </summary>
        /// <returns>true if TotalResults property is set</returns>
        public Boolean IsSetTotalResults()
        {
            return  this.totalResultsField != null;

        }


        /// <summary>
        /// Gets and sets the TotalPages property.
        /// </summary>
        [XmlElementAttribute(ElementName = "TotalPages")]
        public Decimal TotalPages
        {
            get { return this.totalPagesField.GetValueOrDefault() ; }
            set { this.totalPagesField= value; }
        }



        /// <summary>
        /// Sets the TotalPages property
        /// </summary>
        /// <param name="totalPages">TotalPages property</param>
        /// <returns>this instance</returns>
        public Items WithTotalPages(Decimal totalPages)
        {
            this.totalPagesField = totalPages;
            return this;
        }



        /// <summary>
        /// Checks if TotalPages property is set
        /// </summary>
        /// <returns>true if TotalPages property is set</returns>
        public Boolean IsSetTotalPages()
        {
            return  this.totalPagesField != null;

        }


        /// <summary>
        /// Gets and sets the SearchResultsMap property.
        /// </summary>
        [XmlElementAttribute(ElementName = "SearchResultsMap")]
        public SearchResultsMap SearchResultsMap
        {
            get { return this.searchResultsMapField ; }
            set { this.searchResultsMapField = value; }
        }



        /// <summary>
        /// Sets the SearchResultsMap property
        /// </summary>
        /// <param name="searchResultsMap">SearchResultsMap property</param>
        /// <returns>this instance</returns>
        public Items WithSearchResultsMap(SearchResultsMap searchResultsMap)
        {
            this.searchResultsMapField = searchResultsMap;
            return this;
        }



        /// <summary>
        /// Checks if SearchResultsMap property is set
        /// </summary>
        /// <returns>true if SearchResultsMap property is set</returns>
        public Boolean IsSetSearchResultsMap()
        {
            return this.searchResultsMapField != null;
        }




        /// <summary>
        /// Gets and sets the Item property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Item")]
        public List<Item> Item
        {
            get
            {
                if (this.itemField == null)
                {
                    this.itemField = new List<Item>();
                }
                return this.itemField;
            }
            set { this.itemField =  value; }
        }



        /// <summary>
        /// Sets the Item property
        /// </summary>
        /// <param name="list">Item property</param>
        /// <returns>this instance</returns>
        public Items WithItem(params Item[] list)
        {
            foreach (Item item in list)
            {
                Item.Add(item);
            }
            return this;
        }          
 


        /// <summary>
        /// Checks if Item property is set
        /// </summary>
        /// <returns>true if Item property is set</returns>
        public Boolean IsSetItem()
        {
            return (Item.Count > 0);
        }




        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetCorrectedQuery()) {
                CorrectedQuery  correctedQuery = this.CorrectedQuery;
                xml.Append("<CorrectedQuery>");
                xml.Append(correctedQuery.ToXMLFragment());
                xml.Append("</CorrectedQuery>");
            } 
            if (IsSetQid()) {
                xml.Append("<Qid>");
                xml.Append(EscapeXML(this.Qid));
                xml.Append("</Qid>");
            }
            if (IsSetEngineQuery()) {
                xml.Append("<EngineQuery>");
                xml.Append(EscapeXML(this.EngineQuery));
                xml.Append("</EngineQuery>");
            }
            if (IsSetTotalResults()) {
                xml.Append("<TotalResults>");
                xml.Append(this.TotalResults);
                xml.Append("</TotalResults>");
            }
            if (IsSetTotalPages()) {
                xml.Append("<TotalPages>");
                xml.Append(this.TotalPages);
                xml.Append("</TotalPages>");
            }
            if (IsSetSearchResultsMap()) {
                SearchResultsMap  searchResultsMap = this.SearchResultsMap;
                xml.Append("<SearchResultsMap>");
                xml.Append(searchResultsMap.ToXMLFragment());
                xml.Append("</SearchResultsMap>");
            } 
            List<Item> itemList = this.Item;
            foreach (Item item in itemList) {
                xml.Append("<Item>");
                xml.Append(item.ToXMLFragment());
                xml.Append("</Item>");
            }
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}